package com.cvte.boe.media.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.cvte.boe.media.MediaApplication;
import com.cvte.boe.media.utils.LogUtil;

/**
 * Created by wuguitong on 2018/4/9.
 */
public class MountActionReceiver extends BroadcastReceiver {
    private final String TAG = MountActionReceiver.this.getClass().getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        String volumePath = intent.getDataString();
        if (intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)) {
            if (MediaApplication.mListeners != null) {
                for (MediaApplication.MountActionListener lis : MediaApplication.mListeners) {
                    lis.onReceive(volumePath, true);
                }
            }
        } else if (intent.getAction().equals(Intent.ACTION_MEDIA_EJECT) || intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
            if (MediaApplication.mListeners != null) {
                for (MediaApplication.MountActionListener lis : MediaApplication.mListeners) {
                    lis.onReceive(volumePath, false);
                }
            }
        }
    }
}
